/**
 **/
jsx3.lang.Class.defineClass("tibco.admin.enterpriseAssets.envDef.envDtls.medBus.quality.Quality",
        jsx3.gui.Block,
        null,
        function (mediBusQual) {
            mediBusQual.workspace = null;
            mediBusQual.prototype.environmentName = null;
            mediBusQual.prototype.entityID = null;

            mediBusQual.prototype.init = function(strName, vntLeft, vntTop, vntWidth, vntHeight) {
                this.jsxsuper(strName, vntLeft, vntTop, vntWidth, vntHeight);
            };

            mediBusQual.prototype.subscribeAll = function() {
                tibco.admin.PubSub.subscribe(tibco.admin.enterpriseAssets.envDef.EventID.ENVIRONMENT_ROW_SELECTED, this, this.callgetQualityOfService);
            }

            mediBusQual.prototype.unsubscribeAll = function() {
                tibco.admin.PubSub.unsubscribe(tibco.admin.enterpriseAssets.envDef.EventID.ENVIRONMENT_ROW_SELECTED, this);
            }

            mediBusQual.prototype.clearDetails = function() {
                this.doCancel();
                this.getDescendantOfName("btnEdit_27C").setEnabled(jsx3.gui.Form.STATEDISABLED, true);
                this.getDescendantOfName("lblQualityOfService_27C").setText("", true);
            }

            mediBusQual.prototype.doEdit = function() {
                this.handler.beginQOSEditMode();
                this.getDescendantOfName("lytMBInfoShow_27C").setDisplay(jsx3.gui.Block.DISPLAYNONE, true);
                this.getDescendantOfName("lytMBInfoEdit_27C").setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true);
                var QS = this.getDescendantOfName("lblQualityOfService_27C").getText();
                var val = "best_effort";
                if(QS == tibco.admin.Main.getServer().getDynamicProperty("@atleast_once")) {
                    val = "atleast_once";
                }
                else if(QS == tibco.admin.Main.getServer().getDynamicProperty("@atmost_once")) {
                    val = "atmost_once";
                }
                this.getDescendantOfName("selQualityOfService_27C").setValue(val);

            }
            /**
             * Save Quality Of Service.
             */
            mediBusQual.prototype.doSave = function() {
                this.calleditQualityOfService();
            }
            /**
             * Cancel Quality Of Service edit.
             */
            mediBusQual.prototype.doCancel = function() {
                if(this.handler)
                    this.handler.endQOSEditMode();
                this.getDescendantOfName("lytMBInfoShow_27C").setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true);
                this.getDescendantOfName("lytMBInfoEdit_27C").setDisplay(jsx3.gui.Block.DISPLAYNONE, true);
            }

            mediBusQual.prototype.callgetQualityOfService = function(objEvent, useCached) {
                if(this.handler && this.handler.isQOSInEditMode()) {
                    return;
                }
                if(!objEvent) {
                    if(this.lastMsg && useCached) {
                        objEvent = this.lastMsg;
                    }
                }
                else {
                    this.lastMsg = objEvent;
                }
                this.entityID = objEvent ? objEvent.environmentID : null;
                if(this.entityID == null) {
                    this.clearDetails();
                    return;
                }
                this.environmentName = objEvent.environmentName;
                var objService = tibco.admin.Main.loadService("tibco.admin",
                        "tibco/admin/enterpriseAssets/envDef/envDtls/medBus/quality/rules/getQualityOfServiceRule.xml",
                        "getQualityOfService",
                        "get quality of service");
                //subscribe and call
                objService.entityID = objEvent.environmentID;
                objService.environmentName = objEvent.environmentName;
                objService.subscribe(jsx3.net.Service.ON_SUCCESS, this, this.ongetQualityOfServiceSuccess);
                objService.setEndpointURL(tibco.admin.util.ServiceHelper.getEnvironmentEndpointURL());
                objService.doCall();
            };

            mediBusQual.prototype.ongetQualityOfServiceSuccess = function(objEvent) {
                this.getDescendantOfName("btnEdit_27C").setEnabled(jsx3.gui.Form.STATEENABLED, true);
                this.getDescendantOfName("lblQualityOfService_27C", true, false).setText(objEvent.target.deliveryMode, true);
                var val = "best_effort";
                if(objEvent.target.deliveryMode == tibco.admin.Main.getServer().getDynamicProperty("@atleast_once")) {
                    val = "atleast_once";
                }
                else if(objEvent.target.deliveryMode == tibco.admin.Main.getServer().getDynamicProperty("@atmost_once")) {
                    val = "atmost_once";
                }
                this.getDescendantOfName("selQualityOfService_27C", true, false).setValue(val);
            };

            mediBusQual.prototype.calleditQualityOfService = function() {
                var objService = tibco.admin.Main.loadService("tibco.admin",
                        "tibco/admin/enterpriseAssets/envDef/envDtls/medBus/quality/rules/editQualityOfServiceRule.xml",
                        "editQualityOfService",
                        "edit quality of service");

                //subscribe and call
                objService.environmentName = this.environmentName;
                objService.entityID = this.entityID;
                objService.subscribe(jsx3.net.Service.ON_SUCCESS, this, this.oneditQualityOfServiceSuccess);
                objService.setEndpointURL(tibco.admin.util.ServiceHelper.getEnvironmentEndpointURL());
                objService.doCall();
            };

            mediBusQual.prototype.oneditQualityOfServiceSuccess = function(objEvent) {
                this.handler.endQOSEditMode();
                this.getDescendantOfName("lytMBInfoShow_27C").setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true);
                this.getDescendantOfName("lytMBInfoEdit_27C").setDisplay(jsx3.gui.Block.DISPLAYNONE, true);
                this.getDescendantOfName("lblQualityOfService_27C", true, false).setText(this.getDescendantOfName("selQualityOfService_27C").getText(), true);
                this.callgetQualityOfService(null, true);
            };

        });
